package com.agriculture.competition.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.agriculture.competition.domain.JaCompetitionScore;
import com.agriculture.competition.service.IJaCompetitionScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.common.security.annotation.RequiresPermissions;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.page.TableDataInfo;

/**
 * 比赛分数Controller
 * 
 * @author agriculture
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/score")
public class JaCompetitionScoreController extends BaseController
{
    @Autowired
    private IJaCompetitionScoreService jaCompetitionScoreService;

    /**
     * 查询比赛分数列表
     */
    @RequiresPermissions("competition:score:list")
    @GetMapping("/list")
    public TableDataInfo list(JaCompetitionScore jaCompetitionScore)
    {
        startPage();
        List<JaCompetitionScore> list = jaCompetitionScoreService.selectJaCompetitionScoreList(jaCompetitionScore);
        return getDataTable(list);
    }

    /**
     * 导出比赛分数列表
     */
    @RequiresPermissions("competition:score:export")
    @Log(title = "比赛分数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaCompetitionScore jaCompetitionScore)
    {
        List<JaCompetitionScore> list = jaCompetitionScoreService.selectJaCompetitionScoreList(jaCompetitionScore);
        ExcelUtil<JaCompetitionScore> util = new ExcelUtil<JaCompetitionScore>(JaCompetitionScore.class);
        util.exportExcel(response, list, "比赛分数数据");
    }

    /**
     * 获取比赛分数详细信息
     */
    @RequiresPermissions("competition:score:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jaCompetitionScoreService.selectJaCompetitionScoreById(id));
    }

    /**
     * 新增比赛分数
     */
    @RequiresPermissions("competition:score:add")
    @Log(title = "比赛分数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JaCompetitionScore jaCompetitionScore)
    {
        return toAjax(jaCompetitionScoreService.insertJaCompetitionScore(jaCompetitionScore));
    }

    /**
     * 修改比赛分数
     */
    @RequiresPermissions("competition:score:edit")
    @Log(title = "比赛分数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JaCompetitionScore jaCompetitionScore)
    {
        return toAjax(jaCompetitionScoreService.updateJaCompetitionScore(jaCompetitionScore));
    }

    /**
     * 删除比赛分数
     */
    @RequiresPermissions("competition:score:remove")
    @Log(title = "比赛分数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jaCompetitionScoreService.deleteJaCompetitionScoreByIds(ids));
    }
}
